# -*- coding: UTF-8 -*-
"""
@version: 1.0
@PackageName: ApiAutoTest01 - tencent_test2.py
@author: beixun
@Description: 
@since 2025/11/10 16:48
"""
import logging

import requests
from jsonschema import validate
import pytest

class Test:
    @pytest.fixture
    def login(self):
        url = "http://8.137.19.140:9090/user/login"
        data = {
            "username":"zhangsan",
            "password":123456
        }
        r = requests.post(url=url,data=data)
        rsp = r.json()
        json_schema = {
            "type":"object",
            "properties":{
                "code":{
                    "type":"string"
                },
                "errMsg":{
                    "type":"string"
                },
                "data": {
                    "type": "string"
                }
            }
        }
        validate(rsp,json_schema)
        return rsp["data"]

    def test(self,login):
        url = "http://8.137.19.140:9090/blog/getList"
        header = {
            "user_token_header":login
        }
        r = requests.request(method="GET",url=url,headers=header)
        rsp = r.json()
        json = {
            "code": "SUCCESS",
            "errMsg": "",
            "data": [
                {
                    "id": 267386,
                    "title": "测试标题",
                    "content": "##在这里写下一篇博客\n测试博客内容",
                    "userId": 1,
                    "deleteFlag": 0,
                    "createTime": "2025-11-10 16:14",
                    "updateTime": "2025-11-10T08:14:41.000+00:00",
                    "loginUser": False
                },
                {
                    "id": 267387,
                    "title": "测试标题",
                    "content": "##在这里写下一篇博客↵测试博客内容",
                    "userId": 1,
                    "deleteFlag": 0,
                    "createTime": "2025-11-10 16:22",
                    "updateTime": "2025-11-10T08:22:06.000+00:00",
                    "loginUser": False
                },
                {
                    "id": 267388,
                    "title": "接口自动化标题",
                    "content": "接口自动化内容",
                    "userId": 2,
                    "deleteFlag": 0,
                    "createTime": "2025-11-10 16:40",
                    "updateTime": "2025-11-10T08:40:19.000+00:00",
                    "loginUser": False
                },
                {
                    "id": 267389,
                    "title": "接口自动化标题",
                    "content": "接口自动化内容",
                    "userId": 2,
                    "deleteFlag": 0,
                    "createTime": "2025-11-10 16:42",
                    "updateTime": "2025-11-10T08:42:43.000+00:00",
                    "loginUser": False
                },
                {
                    "id": 267390,
                    "title": "花朵",
                    "content": "##在这里写下一篇博客\n[![](https://ts3.tc.mm.bing.net/th/id/OIP-C.vCD7GSVBeEWWjmNvdzq8CgHaE8?cb=ucfimg2ucfimg=1&rs=1&pid=ImgDetMain&o=7&rm=3)](https://ts3.tc.mm.bing.net/th/id/OIP-C.vCD7GSVBeEWWjmNvdzq8CgHaE8?cb=ucfimg2ucfimg=1&rs=1&pid=ImgDetMain&o=7&rm=3)",
                    "userId": 1,
                    "deleteFlag": 0,
                    "createTime": "2025-11-10 16:49",
                    "updateTime": "2025-11-10T08:49:20.000+00:00",
                    "loginUser": False
                }
            ]
        }
        logging.info(f"获取列表{rsp}")
        assert rsp==json
